/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * OSListaUI.java
 *
 * Created on 24/06/2011, 23:29:21
 */

package my.contacteditor;

import java.util.List;
import javax.swing.ButtonGroup;


/**
 *
 * @author Felipe
 */
public class OSListaUI extends javax.swing.JFrame {

    /** Creates new form OSListaUI */
    public OSListaUI() {
        initComponents();
        OS os = new OS();
        listafinal.setModel(os.ListarTodos());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        lblID = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtdataentrega = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtdataprevista = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        comboequipamento = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        comboestagiario = new javax.swing.JComboBox();
        jRadioETB = new javax.swing.JRadioButton();
        jRadioSede = new javax.swing.JRadioButton();
        jRadioCascata = new javax.swing.JRadioButton();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        listafinal = new javax.swing.JTable();
        btnCadastrar = new javax.swing.JButton();
        btnLimpar = new javax.swing.JButton();
        btnAlterar = new javax.swing.JButton();
        btnInicio = new javax.swing.JButton();
        combosituacao = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        mensagem = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jTable2);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("ID:");

        lblID.setText("jLabel2");

        jLabel3.setText("Data de Entrega:");

        txtdataentrega.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtdataentregaActionPerformed(evt);
            }
        });

        jLabel4.setText("Data Prevista da Devolução:");

        jLabel5.setText("Equipamento:");

        comboequipamento.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel6.setText("Unidade de Destino:");

        jLabel7.setText("Estagiario:");

        comboestagiario.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jRadioETB.setText("ETB");
        jRadioETB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioETBActionPerformed(evt);
            }
        });

        jRadioSede.setText("Sede");

        jRadioCascata.setText("Cascata");

        jLabel8.setText("RESUMO DA ORDEM DE SERVIÇO");

        listafinal.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(listafinal);

        btnCadastrar.setText("Cadastrar");
        btnCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCadastrarActionPerformed(evt);
            }
        });

        btnLimpar.setText("Limpar");
        btnLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimparActionPerformed(evt);
            }
        });

        btnAlterar.setText("Alterar");
        btnAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAlterarActionPerformed(evt);
            }
        });

        btnInicio.setText("Inicio");
        btnInicio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInicioActionPerformed(evt);
            }
        });

        combosituacao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "EM CONCERTO", "CONCERTADO", "SEM CONCERTO", "CONCERTO EXTERNO", " " }));

        jLabel2.setText("Situação:");

        jButton1.setText("AVANÇAR");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(74, 74, 74)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(btnCadastrar)
                            .addComponent(jLabel6)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel2)
                                .addComponent(jLabel7)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(119, 119, 119)
                                .addComponent(btnLimpar)
                                .addGap(94, 94, 94)
                                .addComponent(btnAlterar))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(comboestagiario, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(comboequipamento, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(txtdataentrega, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtdataprevista, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE))
                                    .addComponent(combosituacao, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(4, 4, 4)
                                        .addComponent(lblID))
                                    .addComponent(jRadioSede)
                                    .addComponent(jRadioCascata)
                                    .addComponent(jRadioETB))
                                .addGap(43, 43, 43)
                                .addComponent(jButton1))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(213, 213, 213)
                        .addComponent(jLabel8)
                        .addGap(89, 89, 89)
                        .addComponent(btnInicio)))
                .addContainerGap(24, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 645, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(272, 272, 272)
                .addComponent(mensagem)
                .addContainerGap(383, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(mensagem)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblID)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtdataentrega, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtdataprevista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(comboequipamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(comboestagiario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(combosituacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2)))
                    .addComponent(btnInicio))
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioETB)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jRadioSede)
                .addGap(6, 6, 6)
                .addComponent(jRadioCascata)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCadastrar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnLimpar)
                    .addComponent(btnAlterar))
                .addGap(36, 36, 36)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jRadioETBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioETBActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioETBActionPerformed
 private void formWindowActivated(java.awt.event.WindowEvent evt) {
        // TODO add your handling code here:
        //OS os = new OS();
        //listafinal.setModel(os.ListarTodos());

        Equipamento equipamento = new Equipamento();
        List<Equipamento> equipamentos = equipamento.ListarTodosObj();

        for(Equipamento item: equipamentos)
        {
            String texto = String.valueOf(item.getNumeroPatrimonio()) + item.getCarga() + item.getMarca() +item.getNomeEquipamento();
            comboequipamento.addItem(texto);
        }

        //////////////////////////////////////////////////
        Estagiario estagiario = new Estagiario();
        List<Estagiario> estagiarios = estagiario.ListarTodosObj();

        for(Estagiario item: estagiarios)
        {
            String texto = String.valueOf(item.getCodigo()) + " - " + item.getCronograma();
            comboestagiario.addItem(texto);
        }

    }
    private void btnCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCadastrarActionPerformed
String vdatainicio = txtdataentrega.getText();
String vdataprevista = txtdataprevista.getText();

String vequipamento = comboequipamento.getSelectedItem().toString().split(" - ")[0];
String vestagiario = comboestagiario.getSelectedItem().toString().split(" - ")[0];
String vsituacao = combosituacao.getSelectedItem().toString().split(" - ")[0];
//String vunidade
if (jRadioCascata.isSelected() ) {  
      ButtonGroup t1 = new ButtonGroup();  
       t1.getButtonCount();
}  
  
else if (jRadioSede.isSelected() ) {  
      ButtonGroup t2 = new ButtonGroup();  
      
      t2.getButtonCount();
}  
  
else if(jRadioETB.isSelected()) {  
      ButtonGroup t3 = new ButtonGroup();  
                  t3.getButtonCount() ;
}  
        
            // TODO add your handling code here:
    }//GEN-LAST:event_btnCadastrarActionPerformed
private void listagemMouseClicked(java.awt.event.MouseEvent evt) {
int indice = listafinal.getSelectedRow();
        String id = (String)listafinal.getValueAt(indice, 0);
        String datainicio = (String)listafinal.getValueAt(indice, 2);
        String  dataprevista =(String)listafinal.getValueAt(indice, 4);
        String equip = (String)listafinal.getValueAt(indice, 1);
        String estagiario = (String)listafinal.getValueAt(indice, 3);
        String unidadedestino = (String)listafinal.getValueAt(indice, 3);
        String situacao = (String)listafinal.getValueAt(indice, 3);


        //para o alterar tem q buscar o combo selecionado
        txtdataentrega.setText(datainicio);
        txtdataprevista.setText(dataprevista);
        //comboequipamento.setText(equip);
        //comboestagiario.setText(estagiario);
        //combosituacao.setText(situacao);
        lblID.setText(id);

        btnCadastrar.setEnabled(true);
       btnLimpar.setEnabled(true);
    }
private void limparFormulario()
    {
        //lblCodigo.setText("");
        txtdataentrega.setText("");
        txtdataprevista.setText("");
        lblID.setText("");

        btnLimpar.setEnabled(false);
        btnAlterar.setEnabled(false);
    }
    private void txtdataentregaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtdataentregaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtdataentregaActionPerformed

    private void btnAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAlterarActionPerformed
OS os = new OS();

        int vnump = Integer.parseInt(lblID.getText());
        boolean retorno = os.Alterar(txtdataentrega.getText(), vnump, txtdataprevista.getText();

        if(retorno) {
            listafinal.setModel(os.ListarTodos());
            mensagem.setText("");
            btnAlterar.setEnabled(false);
            btnLimpar.setEnabled(false);
            limparFormulario();
        } else {
            mensagem.setText("Não foi possível alterar");
        }        // TODO add your handling code here:
    }//GEN-LAST:event_btnAlterarActionPerformed

    private void btnLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimparActionPerformed
        // TODO add your handling code here:
        txtdataentrega.setText("");
        txtdataprevista.setText("");
        lblID.setText("");
    }//GEN-LAST:event_btnLimparActionPerformed

    private void btnInicioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInicioActionPerformed
ClienteCadastroUI form = new ClienteCadastroUI();
        form.setVisible(true);
        this.dispose();        // TODO add your handling code here:
    }//GEN-LAST:event_btnInicioActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        Situacao form = new Situacao();
        form.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new OSListaUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAlterar;
    private javax.swing.JButton btnCadastrar;
    private javax.swing.JButton btnInicio;
    private javax.swing.JButton btnLimpar;
    private javax.swing.JComboBox comboequipamento;
    private javax.swing.JComboBox comboestagiario;
    private javax.swing.JComboBox combosituacao;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JRadioButton jRadioCascata;
    private javax.swing.JRadioButton jRadioETB;
    private javax.swing.JRadioButton jRadioSede;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JLabel lblID;
    private javax.swing.JTable listafinal;
    private javax.swing.JLabel mensagem;
    private javax.swing.JTextField txtdataentrega;
    private javax.swing.JTextField txtdataprevista;
    // End of variables declaration//GEN-END:variables

}
